package de.thwildau.tm.moses.xabnf.serializer;

import com.google.inject.Inject;
import com.google.inject.Provider;
import de.thwildau.tm.moses.xabnf.services.XabnfGrammarAccess;
import de.thwildau.tm.moses.xabnf.xabnf.Bindings;
import de.thwildau.tm.moses.xabnf.xabnf.ClassBinding;
import de.thwildau.tm.moses.xabnf.xabnf.FieldBinding;
import de.thwildau.tm.moses.xabnf.xabnf.GeneratorModel;
import de.thwildau.tm.moses.xabnf.xabnf.RuleBinding;
import de.thwildau.tm.moses.xabnf.xabnf.Xabnf;
import de.thwildau.tm.moses.xabnf.xabnf.XabnfPackage;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.serializer.acceptor.ISemanticSequenceAcceptor;
import org.eclipse.xtext.serializer.acceptor.SequenceFeeder;
import org.eclipse.xtext.serializer.diagnostic.ISemanticSequencerDiagnosticProvider;
import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor;
import org.eclipse.xtext.serializer.sequencer.AbstractDelegatingSemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.GenericSequencer;
import org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider;
import org.eclipse.xtext.serializer.sequencer.ISemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.ITransientValueService;
import org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient;

@SuppressWarnings("all")
public class XabnfSemanticSequencer extends AbstractDelegatingSemanticSequencer {

	@Inject
	private XabnfGrammarAccess grammarAccess;
	
	public void createSequence(EObject context, EObject semanticObject) {
		if(semanticObject.eClass().getEPackage() == XabnfPackage.eINSTANCE) switch(semanticObject.eClass().getClassifierID()) {
			case XabnfPackage.BINDINGS:
				if(context == grammarAccess.getBindingsRule()) {
					sequence_Bindings(context, (Bindings) semanticObject); 
					return; 
				}
				else break;
			case XabnfPackage.CLASS_BINDING:
				if(context == grammarAccess.getBindingRule() ||
				   context == grammarAccess.getClassBindingRule()) {
					sequence_ClassBinding(context, (ClassBinding) semanticObject); 
					return; 
				}
				else break;
			case XabnfPackage.FIELD_BINDING:
				if(context == grammarAccess.getFieldBindingRule()) {
					sequence_FieldBinding(context, (FieldBinding) semanticObject); 
					return; 
				}
				else break;
			case XabnfPackage.GENERATOR_MODEL:
				if(context == grammarAccess.getGeneratorModelRule()) {
					sequence_GeneratorModel(context, (GeneratorModel) semanticObject); 
					return; 
				}
				else break;
			case XabnfPackage.RULE_BINDING:
				if(context == grammarAccess.getBindingRule() ||
				   context == grammarAccess.getRuleBindingRule()) {
					sequence_RuleBinding(context, (RuleBinding) semanticObject); 
					return; 
				}
				else break;
			case XabnfPackage.XABNF:
				if(context == grammarAccess.getXabnfRule()) {
					sequence_Xabnf(context, (Xabnf) semanticObject); 
					return; 
				}
				else break;
			}
		if (errorAcceptor != null) errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
	}
	
	/**
	 * Constraint:
	 *     (binding+=Binding*)
	 */
	protected void sequence_Bindings(EObject context, Bindings semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (rule=[Rule|ID] className=STRING methodName=STRING?)
	 */
	protected void sequence_ClassBinding(EObject context, ClassBinding semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (name=STRING type=[Rule|ID]? targetName=STRING)
	 */
	protected void sequence_FieldBinding(EObject context, FieldBinding semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (file=STRING language=Language package=STRING? entryRule=[Rule|ID]? encoding=STRING)
	 */
	protected void sequence_GeneratorModel(EObject context, GeneratorModel semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (rule=[Rule|ID] targetRuleName=STRING? fieldBindings+=FieldBinding*)
	 */
	protected void sequence_RuleBinding(EObject context, RuleBinding semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (generatorModel=GeneratorModel bindings=Bindings)
	 */
	protected void sequence_Xabnf(EObject context, Xabnf semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, XabnfPackage.Literals.XABNF__GENERATOR_MODEL) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XabnfPackage.Literals.XABNF__GENERATOR_MODEL));
			if(transientValues.isValueTransient(semanticObject, XabnfPackage.Literals.XABNF__BINDINGS) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XabnfPackage.Literals.XABNF__BINDINGS));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getXabnfAccess().getGeneratorModelGeneratorModelParserRuleCall_0_0(), semanticObject.getGeneratorModel());
		feeder.accept(grammarAccess.getXabnfAccess().getBindingsBindingsParserRuleCall_1_0(), semanticObject.getBindings());
		feeder.finish();
	}
}
